package com.bytedance.video.controller;


import com.bytedance.video.request.PublishVideoActionRequest;
import com.bytedance.video.request.PublishVideoListRequest;
import com.bytedance.video.request.VideoFeedRequest;
import com.bytedance.video.respones.PublishVideoActionResponses;
import com.bytedance.video.respones.PublishVideoListResponses;
import com.bytedance.video.respones.VideoFeedRespones;
import com.bytedance.video.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/douyin")
//@Validated
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * /douyin/feed/ - 视频流接口
     * 不限制登录状态，返回按投稿时间倒序的视频列表，视频数由服务端控制，单次最多30个。
     * 接口类型
     * GET
     *
     * @return
     */
    @GetMapping("/feed")
    public VideoFeedRespones provideVideo(VideoFeedRequest videoFeedRequest) {
        VideoFeedRespones videoFeedRespones = videoService.provideVideo(videoFeedRequest);
        log.info(videoFeedRequest.getLatest_time().toString());
        return videoFeedRespones;
    }


    /**
     * /douyin/publish/action/ - 视频投稿
     * 登录用户选择视频上传。
     * 接口类型
     * POST
     *
     * @return
     */
    @PostMapping("/publish/action")
    public PublishVideoActionResponses publishVideo(
            PublishVideoActionRequest publishVideoActionRequest
    ) throws IOException {
        PublishVideoActionResponses publishVideoActionResponses = videoService.publishVideo(publishVideoActionRequest);
        return publishVideoActionResponses;
    }

    /**
     * /douyin/publish/list/ - 发布列表
     * 登录用户的视频发布列表，直接列出用户所有投稿过的视频。
     * 接口类型
     * GET
     *
     * @return
     */
    @GetMapping("/publish/list")
    public PublishVideoListResponses getUsersVideoList(PublishVideoListRequest publishVideoListRequest) {
        PublishVideoListResponses publishVideoListResponses = videoService.getUsersVideoList(publishVideoListRequest);
        return publishVideoListResponses;
    }

}
